package com.app.milkteaapp.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.app.milkteaapp.bean.Comment;
import com.app.milkteaapp.bean.FindCommentGsonBean;
import com.app.milkteaapp.R;

public class CommentAdapter extends BaseAdapter {

    private List<Comment> objects = new ArrayList<>();

    private Context context;
    private LayoutInflater layoutInflater;

    public CommentAdapter(Context context,List<Comment> objects) {
        this.objects = objects;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public Comment getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.list_item_comment, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews(getItem(position), (ViewHolder) convertView.getTag());
        return convertView;
    }

    private void initializeViews(Comment object, ViewHolder holder) {
        //TODO implement
        holder.tvUsername.setText(object.getUserName()+"");
        holder.tvComment.setText(object.getComment()+"");
        holder.tvScore.setText(object.getScore()+"");
        holder.tvData.setText(object.getDate()+"");
    }

    protected class ViewHolder {
        private TextView tvUsername;
    private TextView tvComment;
    private TextView tvScore;
    private TextView tvData;

        public ViewHolder(View view) {
            tvUsername = (TextView) view.findViewById(R.id.tv_username);
            tvComment = (TextView) view.findViewById(R.id.tv_comment);
            tvScore = (TextView) view.findViewById(R.id.tv_score);
            tvData = (TextView) view.findViewById(R.id.tv_data);
        }
    }
}
